package pe.edu.upc.dsd.mercadolibreres;

import java.sql.Connection;
import java.sql.PreparedStatement;

import java.sql.SQLException;

public class ArticuloDAO extends BaseDAO {

	public void GuardarArticulo(Articulo vo) throws DAOExcepcion {

		String query = "INSERT INTO producto(nomProd, "
				+ "descProd, stockProd, precProd, imagProd, idVendedor) VALUES (?,?,?,?,?,?)";
		Connection con = null;
		PreparedStatement stmt = null;
		try {
			con = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);

			stmt.setString(1, vo.getNombre());
			stmt.setString(2, vo.getDescripcion());
			stmt.setInt(3, vo.getStock());
			stmt.setString(4, vo.getPrecio());
			stmt.setString(5, vo.getImagen());
			stmt.setInt(6, vo.getVendedor());

			int i = stmt.executeUpdate();
			if (i != 1) {
				throw new SQLException("No se pudo insertar");
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}

	}

}
